import { defHttp } from '/@/utils/http/axios';
import { stringFormat } from '/@/utils/common/compUtils';

enum Api {
  list = '/api-search/admin/indices',
  create = '/api-search/admin/index',
  get = '/api-search/admin/index',
  delete = '/api-search/admin/index/delete',
}

/**
 * 查询ES索引列表
 * @param params
 */
export const getIndicesList = (params) => {
  return defHttp.get({ url: Api.list, params });
};

/**
 * 创建ES索引
 * @param params
 */
export const createIndex = (params) => {
  const url = Api.create;
  return defHttp.post({ url: url, params });
};

/**
 * 查询索引
 * @param params
 */
export const getIndex = (params) => {
  return defHttp.get({ url: Api.get, params });
};

/**
 * 删除索引
 * @param params
 */
export const deleteIndex = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
